const TOKEN_KEY = 'jwtToken';
const REFRESH_TOKEN_KEY = 'refreshJwtToken';

export function getJwtToken() {
  return localStorage.getItem(TOKEN_KEY);
}
export function getJwtRefreshToken() {
  return localStorage.getItem(REFRESH_TOKEN_KEY);
}

export function setJwtToken(token) {
  localStorage.setItem(TOKEN_KEY, token);
}
export function setRefreshJwtToken(token) {
  localStorage.setItem(REFRESH_TOKEN_KEY, token);
}

export function removeJwtToken() {
  localStorage.removeItem(TOKEN_KEY);
  localStorage.removeItem(REFRESH_TOKEN_KEY);
}

export function createAuthorizationTokenHeader() {
  const token = getJwtToken();
  if (token) {
    return {
      "Authorization": "Bearer " + token,
      'X-Requested-With': 'XMLHttpRequest',
      'Content-Type': 'application/json'
    };
  } else {
    return {
      'X-Requested-With': 'XMLHttpRequest',
      'Content-Type': 'application/json'
    };
  }
}

export function createAuthorizationRefreshTokenHeader() {
  const token = getJwtRefreshToken();
  if (token) {
    return {
      "Authorization": "Bearer " + token,
      'X-Requested-With': 'XMLHttpRequest',
      'Content-Type': 'application/json'
    };
  } else {
    return {
      'X-Requested-With': 'XMLHttpRequest',
      'Content-Type': 'application/json'
    };
  }
}